package com.future;

import com.future.util.TreeNode;

/**
 * Description: BM31 对称的二叉树
 *
 * @author weiruibai.vendor
 * Date: 2022/8/2 10:23
 */
public class Solution_BM31 {

    public static void main(String[] args) {

        System.out.println(true ^ false);
        System.out.println(true ^ true);
        System.out.println(false ^ true);
        System.out.println(false ^ false);
        Solution_BM31 bm31 = new Solution_BM31();


    }

    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }
        return process(pRoot.left, pRoot.right);
    }

    private boolean process(TreeNode left, TreeNode right) {
       /* if (left == null ^ right == null) {
            return false;
        }
        if (left == null && right == null) {
            return true;
        }*/
        // 以上等价于
        if ((left == null && right != null) || (left != null && right == null)) {
            return false;
        }
        if (left == null && right == null) {
            return true;
        }
        if (left.val == right.val) {
            boolean b = process(left.left, right.right);
            if (!b) {
                return false;
            }
            b = process(left.right, right.left);
            if (!b) {
                return false;
            }
        } else {
            return false;
        }
        return true;
    }
}
